package com.example.manualManagement.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.manualManagement.entity.Manage;
import com.example.manualManagement.mapper.ManageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private ManageMapper manageMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        QueryWrapper<Manage> queryWrapper = new QueryWrapper();
        queryWrapper.eq("username", username);
        Manage manage = manageMapper.selectOne(queryWrapper);

        if(manage == null){
            throw new RuntimeException("用户不存在");
        }
        return new UserDetailsImpl(manage);
    }
}
